#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main()
{
    int stack1[1000],stack2[1000];
    int top1=-1,top2=-1;
    char c;
    int temp;
    int n1,n2;
    scanf("%d %d",&n1,&n2);
    if( n1>n2 )
    {
        //容量小的作为第一个输入栈
        temp = n1;
        n1 = n2;
        n2 = temp;
    }

    while(1)
    {
        scanf("%c",&c);
        if( c=='T') break;
        else if( c=='A')
        {
            scanf("%d",&temp);
            if( top1==n1-1 && top2!=-1)
            {
                //栈1满，栈2不为空
                printf("ERROR:Full\n");
            }
            else if( top1==n1-1)
            {
                //栈1满，栈2为空
                while( top1>-1 )
                {
                    //栈1出栈到栈2
                    stack2[++top2] = stack1[top1--];
                }
                stack1[++top1] = temp;
            }
            else stack1[++top1] = temp;
        }
        else if( c=='D')
        {
            if( top2!=-1)
                printf("%d\n",stack2[top2--]);
            else if( top2==-1 && top1!=-1)
            {
                while(top1>-1)
                {
                    stack2[++top2] = stack1[top1--];
                }

                printf("%d\n",stack2[top2--]);
            }
            else printf("ERROR:Empty");
        }
    }

    return 0;
}
